package epam.com.threads.entities;

import org.apache.log4j.Logger;

import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * User: Yelena_M
 * Date: 05.09.13
 * Time: 18:41
 * To change this template use File | Settings | File Templates.
 */
public class Ship implements Runnable {

    private final static Logger LOGGER = Logger.getLogger(Ship.class);
    private String shipName;

    public Ship() {

    }

    public Ship(String shipName) {
        this.shipName = shipName;
    }

    public String getShipName() {
        return shipName;
    }

    public void setShipName(String shipName) {
        this.shipName = shipName;
    }

    @Override
    public String toString() {
        return "Ship{" +
                "name='" + shipName + '\'' +
                '}';
    }

    public void run() {
        //PropertiesReader propertiesReader = new PropertiesReader();
        //int shipAmount = Integer.parseInt(propertiesReader.getProperties("data.shipAmount"));
        Random randomAction = new Random();

        Port port = Port.getInstance();
        Wharf wharf;
        try {
            //for (int i = 0; i < shipAmount; i++) //для того, чтобы корабли приходили постоянно?
            wharf = port.moor();
            LOGGER.info("Ship " + shipName + " has moor in port " + wharf.getWharfNumber());

            port.makeAction(randomAction.nextInt(3), shipName);

            port.leaveWharf(wharf);
            LOGGER.info("Ship " + shipName + " has left, port # " + wharf.getWharfNumber());
            //}
        } catch (InterruptedException e) {
            LOGGER.error(e);
        }
    }

}
